package stackAndQueue;

import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

public class TwoQueueMakeStack<T> {

  private Queue<T> queue1 = new LinkedBlockingQueue<>();
  private Queue<T> queue2 = new LinkedBlockingQueue<>();


  public void push(T element) {
    queue1.add(element);
  }

  public T pop() {
    while (queue1.size() > 1) {
      queue2.add(queue1.remove());
    }
    T element = queue1.remove();

    queue1 = queue2;
    queue2 = new LinkedBlockingQueue<>();

    return element;
  }


  public static void main(String args[]) {
    TwoQueueMakeStack stack = new TwoQueueMakeStack();
    stack.push(1);
    stack.push(2);
    stack.push(3);
    System.out.println(stack.pop());
    System.out.println(stack.pop());
    System.out.println(stack.pop());
  }
}
